- group_id = @cluster.group.id if @cluster.group_type?

- if @cluster.project_type?
  - group_id = @cluster.project.group.id if @cluster.project.group
  - user_id = @cluster.project.namespace.owner_id unless group_id

- if can?(current_user, :admin_cluster, @cluster)
  - unless @cluster.provided_by_user?
    .sub-section.form-group
      %h4
        = @cluster.provider_label
      %p
        - provider_link = link_to(@cluster.provider_label, @cluster.provider_management_url, target: '_blank', rel: 'noopener noreferrer')
        = html_escape(s_('ClusterIntegration|Manage your Kubernetes cluster by visiting %{provider_link}')) % { provider_link: provider_link }

  .sub-section.form-group
    = gitlab_ui_form_for @cluster, url: clusterable.cluster_path(@cluster), as: :cluster, html: { class: 'cluster_management_form' } do |field|
      %h4
        = s_('ClusterIntegration|Cluster management project')

      .js-vue-project-select{ data: { label: _('Select a cluster management project'),
          input_name: 'cluster[management_project_id]',
          input_id: 'cluster[management_project_id]',
          order_by: 'last_activity_at',
          group_id: group_id,
          user_id: user_id,
          with_shared: true.to_s,
          include_subgroups: true.to_s,
          membership: true.to_s,
          selected: @cluster.management_project_id } }
      %p.text-muted.gl-mt-n5
        = html_escape(s_('ClusterIntegration|A cluster management project can be used to run deployment jobs with Kubernetes %{code_open}cluster-admin%{code_close} privileges.')) % { code_open: '<code>'.html_safe, code_close: '</code>'.html_safe }
        = link_to _('More information'), help_page_path('user/clusters/management_project.md'), target: '_blank', rel: 'noopener noreferrer'
      = field.submit _('Save changes'), pajamas_button: true

  .sub-section.form-group
    %h4
      = s_('ClusterIntegration|Clear cluster cache')
    %p
      = s_("ClusterIntegration|Clear the local cache of namespace and service accounts.")
      - if @cluster.managed?
        = s_("ClusterIntegration|This is necessary if your integration has become out of sync. The cache is repopulated during the next CI job that requires namespace and service accounts.")
      - else
        = s_("ClusterIntegration|This is necessary to clear existing environment-namespace associations from clusters previously managed by GitLab.")
    = render Pajamas::ButtonComponent.new(method: :delete, href: clusterable.clear_cluster_cache_path(@cluster)) do
      = s_('ClusterIntegration|Clear cluster cache')

  .sub-section.form-group
    %h4.text-danger
      = s_('ClusterIntegration|Remove Kubernetes cluster integration')
    %p
      = s_("ClusterIntegration|Remove this Kubernetes cluster's configuration from this project. This will not delete your actual Kubernetes cluster.")

    #js-cluster-remove-actions{ data: { cluster_path: clusterable.cluster_path(@cluster),
      cluster_name: @cluster.name,
      has_management_project: @cluster.management_project_id? } }
